package com.keter.framework.cloud.component.interceptor;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;

/**
 * Feign请求拦截器
 */
@Configuration
public class FeignInterceptor implements RequestInterceptor {
    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Override
    public void apply(RequestTemplate template) {
    }

    /**
     * 通过ThreadLocal为基于Feign的请求自动添加SID消息头：
     * 目前无法实现！因Hystrix熔断机制导致无法获取ThreadLocal内容
     * @param template
     */
//    private void addSidOfThreadLocal(RequestTemplate template) {
//        logger.info("FeignInterceptor tid:{}",Thread.currentThread().getId());
//        template.header(SIDHolder.KEY_SID, String.valueOf(sidHolder.getOrGenerate()));
//        logger.info("为 Feign Request 生成SID：{}", sidHolder.get());
//    }
}